(define (make-account password balance)
    (define (withdraw amount)
        (cond            
            ((< balance amount) "Insufficient funds")
            (else 
                (begin
                    (set! balance (- balance amount))
                    balance
                )
            )
        )
    )
    (define (deposit amount)
        (set! balance (+ balance amount))
        balance
    )
    (define (dispatch pwd m)
        (display "m=")
        (display m)
        (newline)
        (if (eq? pwd password)
            (cond 
                ((eq? m `withdraw) withdraw)
                ((eq? m `deposit) deposit)
                (else (error "...." m))
            )    
            (lambda (x) 
            "Incorrect password"
            )
        )
        
    )
    dispatch
)

(define acc (make-account  `secret-password 100))
(display ((acc `secret-password `withdraw) 40))
(newline)


(define (make-joint account old-password new-password)
    (lambda (newpwd m) 
        (if (eq? new-password newpwd)
            (lambda(x)
                (display x)
                ((account old-password m) x)
            )    
            (error "password error" newpwd)
        )
    )
)

(define paul-acc
    (make-joint acc `secret-password `resebud)
)

(display ((paul-acc `resebud `deposit) 50))
(exit)